﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using WordNet.Core;
using WordNet.Core.ElementContracts;
using WordNet.Core.DataContract;

namespace WordNet.CoreTests.Parsers
{
    [TestClass]
    public class UnitTestIndexLineNoun:UnitTestBase
    {
        const string NOUN_LINE = "dog n 7 5 @ ~ #m #p %p 7 1 02064081 09963790 09874274 09740502 07571296 03857710 02685221 ";
        
        [ClassInitialize]
        public static void ClassInit(TestContext context)
        {
            Container = MEFLoader.Load();
        }
           
        [TestMethod]
        public void CanParseNoun()
        {
            IParser<IIndexWord> indexLineParser = Container.GetExportedValue<IParser<IIndexWord>>();
            IIndexWord indexWord = indexLineParser.Parse(NOUN_LINE);
            Assert.IsNotNull(indexWord);

        }

        [TestMethod]
        public void CanParseLemma()
        {
            IParser<IIndexWord> indexLineParser = Container.GetExportedValue<IParser<IIndexWord>>();
            IIndexWord indexWord = indexLineParser.Parse(NOUN_LINE);
            Assert.IsNotNull(indexWord);
            string expectedLemma = "dog";
            Assert.AreEqual(expectedLemma, indexWord.Lemma);

        }

        [TestMethod]
        public void CanParseSyntacticCategory()
        {
            IParser<IIndexWord> indexLineParser = Container.GetExportedValue<IParser<IIndexWord>>();
            IIndexWord indexWord = indexLineParser.Parse(NOUN_LINE);
            Assert.IsNotNull(indexWord);
            POS expectedPOS = POS.NOUN;

            Assert.AreEqual(expectedPOS, indexWord.PartOfSpeech);

        }

        [TestMethod]
        public void CanParsePointers()
        {
            IParser<IIndexWord> indexLineParser = Container.GetExportedValue<IParser<IIndexWord>>();
            IIndexWord indexWord = indexLineParser.Parse(NOUN_LINE);
            Assert.IsNotNull(indexWord);
            int expected_pointer_count = 5;
            Assert.AreEqual(expected_pointer_count, indexWord.GetPointers().Count);
            Assert.IsTrue(indexWord.GetPointers().Contains(Pointer.GetPointerType("@", POS.NOUN)));
            Assert.IsTrue(indexWord.GetPointers().Contains(Pointer.GetPointerType("~", POS.NOUN)));
            Assert.IsTrue(indexWord.GetPointers().Contains(Pointer.GetPointerType("#m", POS.NOUN)));
            Assert.IsTrue(indexWord.GetPointers().Contains(Pointer.GetPointerType("#p", POS.NOUN)));
            Assert.IsTrue(indexWord.GetPointers().Contains(Pointer.GetPointerType("%p", POS.NOUN)));

            Assert.IsFalse(indexWord.GetPointers().Contains(Pointer.GetPointerType("#s", POS.NOUN)));
        }

        [TestMethod]
        public void CanParseTagSenseCount()
        {
            IParser<IIndexWord> indexLineParser = Container.GetExportedValue<IParser<IIndexWord>>();
            IIndexWord indexWord = indexLineParser.Parse(NOUN_LINE);
            int expectedTagSenseCount = 1;
            Assert.AreEqual(expectedTagSenseCount, indexWord.TagSenseCount);
        }

        [TestMethod]
        public void CanParseSynsetOffset()
        {
            IParser<IIndexWord> indexLineParser = Container.GetExportedValue<IParser<IIndexWord>>();
            IIndexWord indexWord = indexLineParser.Parse(NOUN_LINE);
            int expectedOffsetCount = 7;
            Assert.AreEqual(expectedOffsetCount, indexWord.GetWordIDs().Count);
            foreach (var wordId in indexWord.GetWordIDs())
            {
                Assert.AreEqual("dog", wordId.Lemma);
                Assert.AreEqual(POS.NOUN, wordId.PartOfSpeech);
            }
            Assert.AreEqual(int.Parse("02064081"), indexWord.GetWordIDs()[0].SynsetID.Offset);
            Assert.AreEqual(POS.NOUN, indexWord.GetWordIDs()[0].SynsetID.PartOfSpeech);
            Assert.AreEqual(int.Parse("09963790"), indexWord.GetWordIDs()[1].SynsetID.Offset);
            Assert.AreEqual(POS.NOUN, indexWord.GetWordIDs()[1].SynsetID.PartOfSpeech);
            Assert.AreEqual(int.Parse("09874274"), indexWord.GetWordIDs()[2].SynsetID.Offset);
            Assert.AreEqual(POS.NOUN, indexWord.GetWordIDs()[2].SynsetID.PartOfSpeech);
            Assert.AreEqual(int.Parse("09740502"), indexWord.GetWordIDs()[3].SynsetID.Offset);
            Assert.AreEqual(POS.NOUN, indexWord.GetWordIDs()[3].SynsetID.PartOfSpeech);
            Assert.AreEqual(int.Parse("07571296"), indexWord.GetWordIDs()[4].SynsetID.Offset);
            Assert.AreEqual(POS.NOUN, indexWord.GetWordIDs()[4].SynsetID.PartOfSpeech);
            Assert.AreEqual(int.Parse("03857710"), indexWord.GetWordIDs()[5].SynsetID.Offset);
            Assert.AreEqual(POS.NOUN, indexWord.GetWordIDs()[5].SynsetID.PartOfSpeech);
            Assert.AreEqual(int.Parse("02685221"), indexWord.GetWordIDs()[6].SynsetID.Offset);
            Assert.AreEqual(POS.NOUN, indexWord.GetWordIDs()[6].SynsetID.PartOfSpeech);

        }
    }
}
